#include <iostream>
#include <vector>
#include <functional>

using namespace std;

typedef function<void()> task_t;

void Download()
{
    cout << "我是一个下载任务" << " 处理者:" << getpid() << endl;
}

void PrintLog()
{
    cout << "我是一个打印日志的任务" << " 处理者:" << getpid() << endl;
}

void PushVideoStream()
{
    cout << "这是一个推送视频流的任务" << " 处理者:" << getpid() << endl;
}

class Init
{
public:
    const static int g_download_code = 0;
    const static int g_printlog_code = 1;
    const static int g_pushvideostream_code = 2;

    vector<task_t> tasks;

public:
    Init()
    {
        tasks.push_back(Download);
        tasks.push_back(PrintLog);
        tasks.push_back(PushVideoStream);

        srand(time(nullptr) ^ getpid());
    }

    bool CheckSafe(int code)
    {
        return code >= 0 && code < tasks.size();
    }

    void RunTask(int command)
    {
        tasks[command]();
    }

    int SelectTask()
    {
        return rand() % tasks.size();
    }

    string ToDesc(int command)
    {
        switch (command)
        {
            case g_download_code:
            {
                return "Download";
                break;
            }
            case g_printlog_code:
            {
                return "PrintLog";
                break;
            }
            case g_pushvideostream_code:
            {
                return "PushVideoStream";
                break;
            }
            default:
            {
                return "Unkown";
                break;
            }
        }
    }
};

Init init;